package com.wc.alorithm_blue_bridge._思维.Q1374;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.StreamTokenizer;

/**
 * @Author congge
 * @Date 2023/11/5 10:09
 * @description 锻造兵器
 * https://www.lanqiao.cn/problems/1374/learning/?page=2&first_category_id=1&sort=students_count&second_category_id=8
 */
public class Main {
    public static void main(String[] args) {
        Input sc = new Input();
        int n = sc.nextInt();
        int k = sc.nextInt();
        int maxN = 10000;
        int[] array = new int[maxN + 1];
        int maxNum = 0;
        for (int i = 0; i < n; i++) {
            int num = sc.nextInt();
            maxNum = Math.max(num,maxNum);
            array[num]++;
        }
        long ans = 0;
        for (int i = k; i <= maxNum; i++) {
            ans += ((long) array[i - k] * array[i]);
        }
        System.out.println(ans);
    }

    static class Input {
        StreamTokenizer in = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));

        public int nextInt() {
            try {
                in.nextToken();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return (int) in.nval;
        }
    }
}
